# 基于Node镜像来安装Vue.js应用的依赖
FROM node:20.18.1-alpine3.20 as build-stage
 
# 设置工作目录
WORKDIR /app
 
# 复制package.json和package-lock.json以安装准确的依赖
COPY package*.json ./

# 设置镜像源
RUN npm config set registry https://registry.npmmirror.com/
 
# 安装项目依赖
RUN npm install
 
# 复制项目文件和目录到工作目录
COPY . .
 
# 构建Vue.js应用
RUN npm run build
 
# 从Nginx基础镜像开始新的构建阶段
FROM nginx as production-stage
 
# 从构建阶段复制构建结果到Nginx目录
COPY --from=build-stage /app/dist /usr/share/nginx/html
 
# 暴露80端口
EXPOSE 80
 
# 启动Nginx，并且Nginx将持续运行
CMD ["nginx", "-g", "daemon off;"]